package com.base.myproject.server.busi;

import com.base.myproject.server.Config;
import com.base.myproject.server.User;
import com.base.myproject.server.database.PoolMan;

public class MenuDB {

	static MenuDB menudb=null;
	private MenuDB()
	{
		
	}
	public static MenuDB getInstance()
	{
		if(menudb==null)
		{
			menudb = new MenuDB();
		}
		return menudb;
		
	}
	public String loadMenu(User u, String system) throws Exception
	{
		 
		String str ="";
		
		//String sql = "select * from menu order by menucode  ";
		String newSystem = "";
		if (system.indexOf("manager") > 0) 
			newSystem = "manager.html";
		if (system.indexOf("oa") > 0) 
			newSystem = "oa.html";
		String sql ;
		if(Config.isRoot(u.getName())) {
			sql = "select * from menu where system = '" + newSystem + "' or menucode like 'Z%'  order by menucode";
		}
		else
		{
			sql = "select * from menu  where menucode in (select menucode from menupermissions where groupicode in (select groupicode from basegroupmenber where bcode ='"+u.getBcode()+"')) and system = '" + newSystem + "' order by menucode";
		}
		PoolMan pm = new PoolMan();
		str = pm.executeQueryXML(sql);
	
		return str;
	}
	
	public static void main()
	{
		System.out.println("--");
	}
}
